package com.zoroki.student_score_system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zoroki.student_score_system.domain.User;
import com.zoroki.student_score_system.domain.UserClass;
import com.zoroki.student_score_system.service.UserClassService;
import com.zoroki.student_score_system.mapper.UserClassMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【user_class】的数据库操作Service实现
* @createDate 2025-06-30 12:49:22
*/
@Service
public class UserClassServiceImpl extends ServiceImpl<UserClassMapper, UserClass>
    implements UserClassService{
    @Autowired
    UserClassMapper userClassMapper;
    @Override
    public List<UserClass> getUserClassList() {
        return userClassMapper.selectList(null);
    }

    @Override
    public UserClass getUserClassByUserId(int userId) {
        QueryWrapper<UserClass> eq = new QueryWrapper<UserClass>().eq("userId", userId);
        return userClassMapper.selectOne(eq);
    }

    @Override
    public UserClass getUserClassByClassId(int classId) {
        QueryWrapper<UserClass> eq = new QueryWrapper<UserClass>().eq("classId", classId);
        return userClassMapper.selectOne(eq);
    }

    @Override
    public boolean addUserClass(UserClass userClass) {
        return userClassMapper.insert(userClass) > 0;
    }

    @Override
    public boolean updateUserClass(UserClass userClass) {
        return userClassMapper.updateById(userClass) > 0;
    }

    @Override
    public boolean deleteUserClass(int userId) {
        QueryWrapper<UserClass> eq = new QueryWrapper<UserClass>().eq("user_id", userId);
        return userClassMapper.delete(eq) > 0;
    }
}




